package com.zgxt.demo.controller;


import com.alibaba.fastjson.JSONObject;
import com.zgxt.demo.entity.UpdateLog;
import com.zgxt.demo.service.UpdateLogService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UpdateLogController {




    @Resource
    private UpdateLogService updateLogService;


    @RequestMapping("/log")
    public List<UpdateLog> LogList(){
        return updateLogService.UpdateLogList();
    }


    @PostMapping("/addLog")
    public String addLog(@RequestParam("logTitle") String logTitle, @RequestParam("logData") String logData, @RequestParam("logVersion") String logVersion){
        JSONObject _out=new JSONObject();
        if (updateLogService.addUpdateLog(logTitle,logData,logVersion)>0){
            _out.put("code",200);
            _out.put("msg","添加日志成功");
        }else {
            _out.put("code",500);
            _out.put("msg","添加日志失败");
        }
        return _out.toJSONString();
    }

    @PostMapping("/deleteLog")
    public String deleteLog(@RequestParam("ids") String ids){
        JSONObject _out=new JSONObject();
        if (updateLogService.deletelog(ids)>0){
            _out.put("code",200);
            _out.put("msg","删除日志成功");
        }else {
            _out.put("code",500);
            _out.put("msg","删除日志失败");
        }
        return _out.toJSONString();
    }

    @PostMapping("/updateLog")
    public String updateLog(@RequestParam("id") Integer id,@RequestParam("logTitle") String logTitle, @RequestParam("logData") String logData, @RequestParam("logVersion") String logVersion){
        JSONObject _out=new JSONObject();
        if (updateLogService.updateLog(id,logTitle,logData,logVersion)>0){
            _out.put("code",200);
            _out.put("msg","更新日志成功");
        }else {
            _out.put("code",500);
            _out.put("msg","更新日志失败");
        }
        return _out.toJSONString();
    }
}
